package com.toommi.refuse.service.impl;

import com.toommi.refuse.entity.Area;
import com.toommi.refuse.mapper.AreaMapper;
import com.toommi.refuse.service.AreaService;
import lombok.AllArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

/**
 * @author yangg
 * @since 2019-07-24 15:27
 */
@Service
@AllArgsConstructor
public class AreaServiceImpl implements AreaService {

    private AreaMapper areaMapper;

    @Override
    public Area addArea(Area area) {
        if (StringUtils.isEmpty(area.getId())) {
            area.setId(UUID.randomUUID().toString());
        }
        areaMapper.insert(area);
        return area;
    }

    @Override
    public List<Area> findAreasByParent(String parent) {

        Area area = new Area();
        area.setParent(parent);
        return areaMapper.select(area);
    }
}
